layui.use(['form','jquery'], function(){

	var form = layui.form;

	//监听提交
	form.on('submit(ok)', function(data){
		var url = "/logic/logic_shares/save";
		let rows = layui.table.cache['table_list'];
		data.field.emails = rows;
		return CommonUtil.layuiEditPageSaveOnSubmit(url,data.field,"search");
	});

	//表单验证 value：表单的值、item：表单的DOM对象
	form.verify({
		code: function(value, item){
			if(CommonUtil.isEmpty(value)){
				return '股票编码不能为空';
			}
			if(value.length != 6){
				return '股票编码输入错误';
			}
		},
		name: function(value, item){
			if(CommonUtil.isEmpty(value)){
				return '股票名称不能为空';
			}
			if(value.length > 8){
				return '股票名称长度必须小于8';
			}
		},
		maxPrice: function(value, item){
			if(isNaN(value)){
				return "这里只能输入数字";
			}
		},
		currentCostPrice: function(value, item){
			if(isNaN(value)){
				return "这里只能输入数字";
			}
		},
		buyPrice: function(value, item){
			if(CommonUtil.isEmpty(value)){
				return '设定购买价格不能为空';
			}
			console.log(isNaN(value))
			if(isNaN(value)){
				return "这里只能输入数字";
			}
		},
		sellPrice: function(value, item){
			if(isNaN(value)){
				return "这里只能输入数字";
			}
		},
	});
	layui.jquery(function(){
		layui.jquery("input[name='code']").blur(function(){
			var code = layui.jquery("input[name='code']").val();
			if (!code){
				return;
			}
			layui.jquery.post('/logic/logic_shares/checkCode',{code:code},function (data) {
				console.log(data)
				if (data.fail){
					layer.alert(data.msg);
				}
			});
		})

	});
});
